package com.zz.controller;

import com.zz.pojo.User;
import com.zz.service.UserService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
    * @Date: 13:47 2021/8/5
    * @Param: []
    * @return: java.util.List<com.zz.pojo.User>
    * @Description: 查询所有用户
    **/
    @GetMapping("findAll")
    public List<User> findAll(){
        return userService.findAll();
    }
    
    /**
    * @Date: 15:46 2021/8/5
    * @Param: [id]
    * @return: com.zz.pojo.User
    * @Description: 通过id查询用户 
    **/
    @GetMapping("findById")
    public User findById(Integer id){
        return userService.findById(id);
    }
    
    /**
    * @Date: 16:11 2021/8/5
    * @Param: [name, sex]
    * @return: java.util.List<com.zz.pojo.User>
    * @Description:  根据姓名和性别模糊查询
    **/
    @GetMapping("findNameAndSex")
    public List<User> findNameAndSex(String name,String sex){
        return userService.findNameAndSex(name,sex);
    }

    /**
    * @Date: 16:40 2021/8/5
    * @Param: [name]
    * @return: com.zz.pojo.User
    * @Description: 更新某个用户的名字
    **/
    @GetMapping("updateName")
    public int updateName(Integer id,String name){
        return userService.updateName(id,name);
    }

    /**
    * @Date: 17:17 2021/8/5
    * @Param: [id]
    * @return: int
    * @Description: 根据id删除某个用户
    **/
    @GetMapping("deleteById")
    public int deleteById(Integer id){
        return userService.deleteById(id);
    }

    /**
    * @Date: 17:27 2021/8/5
    * @Param: [id, name, username, sex, age]
    * @return: int
    * @Description: 新增用户
    **/
    @GetMapping("insertUser")
    public int insertUser(Integer id,String name,String username,String sex,Integer age){
        return userService.insertUser(id,name,username,sex,age);
    }
    
    

}
